package game.web.base;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	private DateUtils(){
		
	}
	
	public static String getCurrentDate(String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(new Date());
	}
	//获取本周星期一的日期
	public static String getMondayDate(String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.MONDAY);
		c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
		return sdf.format(c.getTime());
	}
	//获取本周星期日的日期
	public static String getSundayDate(String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.MONDAY);
		c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6);
		return sdf.format(c.getTime());
	}
	//获取本月第一天的日期
	public static String getFirstDateOfMonth(String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Calendar c = Calendar.getInstance();
		c.set(Calendar.DATE, 1);
		return sdf.format(c.getTime());
	}
	//获取本月最后一天的日期
	public static String getLastDateOfMonth(String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Calendar c = Calendar.getInstance();
		c.set(Calendar.DATE, 1);
		c.add(Calendar.MONTH, 1);
		c.add(Calendar.DATE, -1);
		return sdf.format(c.getTime());
	}
}
